{% extends "mall/base.html" %} {% block title %} {{ text }} {% endblock %} {%
block css %}
<style>
  .bgcolor {
    background-color: #fff;
  }

  .container {
    height: 100%;
    overflow-y: auto;
  }

  .container > div {
    background-color: #fff;
  }

  .weui_msg {
    padding-top: 36px;
    text-align: center;
  }

  .weui_msg .weui_icon_area {
    margin-bottom: 30px;
  }

  .weui_msg .weui_text_area {
    margin-bottom: 25px;
    padding: 0 20px;
  }

  .weui_msg .weui_opr_area {
    margin-bottom: 25px;
  }

  .weui_msg .weui_extra_area {
    margin-bottom: 15px;
    font-size: 14px;
    color: #888;
  }

  .weui_btn_primary {
    background-color: #18b4ed;
    color: #fff;
  }

  .weui_btn {
    position: relative;
    display: block;
    margin-left: auto;
    margin-right: auto;
    padding-left: 14px;
    padding-right: 14px;
    box-sizing: border-box;
    font-size: 18px;
    text-align: center;
    text-decoration: none;
    color: #ffffff;
    line-height: 2.33333333;
    border-radius: 5px;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
    overflow: hidden;
  }

  .weui_msg .weui_msg_title {
    margin-bottom: 5px;
    font-weight: 400;
    font-size: 20px;
  }

  .weui_msg .weui_msg_desc {
    font-size: 14px;
    color: #888;
  }

  .weui_icon_success {
    width: 133px;
    height: 133px;
  }

  .weui_btn_area {
  }
</style>
{% endblock %} {% block header %} {% endblock %} {% block content %}
<div class="container" id="container">
  <div class="msg">
    <div class="weui_msg">
      <div class="weui_icon_area">
        <img
          class="weui_icon_success"
          src="{{ STATIC_URL }}/static/img/wechat-pay.png"
        />
      </div>

      <div class="weui_text_area">
        <h2 class="weui_msg_title" id="divResult">支付请求中,请稍后...</h2>
      </div>
      <div class="weui_opr_area">
        <p class="weui_btn_area">
          订单号：{{ trade_no }}
        </p>
      </div>
    </div>
  </div>
</div>
<div id="debug"></div>
{% endblock %} {% block footer %} {% endblock %} {% block js %}
<script src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script>
  var debug = false;
  var appId = "{{ app_id }}";
  // 时间戳
  var timeStamp = "{{ time_stamp }}";
  // 随机字符串
  var nonceStr = "{{ nonce_str }}";
  var prepay_id = "{{ prepay_id }}";
  var signature = "{{ signature }}";
  var sign = "{{ sign_value }}";
  var full_url = "{{ full_url }}";
  var order_type = "{{ order_type }}";
  var describe = "{{ describe }}";
  var serial_id = "{{ serial_id }}";
  var gift_key = "{{ gift_key }}";
  var order_id = "{{ order_id }}";

  $(function() {
    wx.config({
      debug: debug, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
      appId: appId, // 必填，公众号的唯一标识
      timestamp: timeStamp, // 必填，生成签名的时间戳
      nonceStr: nonceStr, // 必填，生成签名的随机串
      signature: signature, // 必填，签名，见附录1
      jsApiList: ["chooseWXPay"] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
    });
    wx.ready(function() {
      // 调起微信支付
      wx.chooseWXPay({
        appId: appId,
        timestamp: timeStamp, // 支付签名时间戳，注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
        nonceStr: nonceStr, // 支付签名随机串，不长于 32 位
        package: "prepay_id=" + prepay_id, // 统一支付接口返回的prepay_id参数值，提交格式如：prepay_id=***）
        signType: "MD5", // 签名方式，默认为'SHA1'，使用新版支付需传入'MD5'
        paySign: sign, // 支付签名
        success: function(res) {
          // 支付成功后的回调函数
          if (res.errMsg == "chooseWXPay:ok") {
            $("#divResult").text("支付成功!");
            $("#divSuccess").show();
            if (order_type == 6) {
              // 旧礼品卡跳转============================================
              // location.href =
              //  "/static/giftcard/index.html#/activateSucceed?id=" +
              //  serial_id +
              //  "&code=" +
              //  gift_key;
              // =====================================================

              // 送礼订单支付成功跳转
              location.href =
                "/static/app1/index.html#/sendFriends?order_id=" +
                order_id +
                "&key=" +
                gift_key;
            } else if (order_type == 8) {
              location.href =
                "/static/winecard/index.html#/freecardPaySucceed?orderAmount={{ fee }}&orderId={{ trade_no }}&storeName={{ store_name }}";
            } else if (order_id) {
              location.href =
                "/order/{{ order_id }}"; // 体验订单
            } else if (describe == "新事业合伙人注册") {
              location.href = "/admin/partner";
            } else if (describe != "adfunding") {
              location.href = "/static/partners3/index.html#/successfulStay"; // 后台
            } else {
              location.href = "/static/app/index.html#/paymentSuccessful"; // 订单列表
            }
          } else {
            alert(JSON.stringify(res));
          }
        },

        cancel: function(res) {
          if (res.errMsg == "chooseWXPay:cancel") {
            if (order_type == 6) {
              // location.href =
              //   "/static/giftcard/index.html#/activateFailed?id=" +
              //   serial_id +
              //   "&code=" +
              //   gift_key;

              // 跳转未支付订单
              location.href = "/static/app1/index.html#/myOrder?code=1"
            } else if (order_type == 8) {
              location.href =
                "/static/winecard/index.html#/freecardPayFailed?storeId={{ store_id }}&storeName={{ store_name }}";
            } else if (order_id) {
              location.href =
                "/order/{{ order_id }}"; // 体验订单
            } else if (describe == "crowdfunding") {
              location.href = "/static/share/crowd-funding/index.html"; // 托管经营
            } else if (describe == "partnershop") {
              location.href = "/static/share/partnershop/index.html"; // 联合经营
            } else if (describe == "delegate") {
              location.href = "/static/share/delegate/index.html"; // 委托经营
            } else if (describe == "新事业合伙人注册") {
              window.history.go(-2);
            } else {
              location.href = "/static/share/ad-funding/index.html"; // 广告众筹
            }
          }
        }
      });
    });
    wx.error(function(res) {
      alert("调用错误");
      alert(JSON.stringify(res));
    });

    function showDebug(k, v) {
      // 显示调试信息
      var html = "<p>";
      html += k + ":" + v;
      html += "</p>";
      $("#debug").append(html);
    }

    if (debug) {
      showDebug("appid", appId);
      showDebug("timeStamp", timeStamp);
      showDebug("nonceStr", nonceStr);
      showDebug("prepay_id", prepay_id);
      showDebug("signature", signature);
      showDebug("sign", sign);
      showDebug("full_url", full_url);
    }
  });
</script>

<script>
  function moveon() {
    var answer = confirm("微信支付有时会有系统繁忙或延迟现象，请稍后再试。");
    if (answer) {
      location.href = "/order/{{ trade_no }}";
    }
  }
  // 超时显示跳转弹窗
  setTimeout(moveon, 60000);
</script>
{% endblock %}
